﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Weever.JKScroller
{
    public class WinUser
    {
        public const int WM_HOTKEY = 0x0312;
        public const int WM_MOUSEWHEEL = 0x20A;
        public const int WM_MOUSEHWHEEL = 0x020E;
        public const int WM_MBUTTONDOWN = 0x207;
        public const int WM_MBUTTONUP = 0x208;

        public const int MOD_ALT = 1;
        public const int MOD_CONTROL = 2;
        public const int MOD_SHIFT = 4;
        public const int MOD_WIN = 8;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

        [DllImport("User32.dll")]
        public static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);

        [DllImport("User32.dll", SetLastError = true)]
        public static extern int UnregisterHotKey(IntPtr hwnd, int id);

        [DllImport("User32.dll")]
        public static extern IntPtr WindowFromPoint(Point p);

        public static Point LParamToPoint(IntPtr lParam)
        {
            long lParam64 = lParam.ToInt64();
            return new Point((int)(lParam64 & 0x0000FFFF),
                             (int)(lParam64 >> 16));
        }

        public static IntPtr PointToLParam(Point p)
        {
            long res = p.Y << 16;
            res |= p.X & 0x0000FFFF;
            return (IntPtr) res;
        }
    }
}